<!DOCTYPE html>


  <html class="dark page-post">


<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  
  <title>浅析JSON.stringify | Poetry&#39;s Blog</title>

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

  
    <meta name="keywords" content="JavaScript,">
  

  <meta name="description" content="一、JSON.stringify参数详解 stringify方法顾名思义，就是把JSON序列化，其语法如下  JSON.stringify(value [, replacer] [, space])  value：是必选字段。就是你输入的对象、如数组等 replacer：这个是可选的。它又分为2种方式，一种是数组，第二种是方法【过滤函数，或者key的过滤数组（只有在数组中的会展示）】 情况一：re">
<meta name="keywords" content="JavaScript">
<meta property="og:type" content="article">
<meta property="og:title" content="浅析JSON.stringify">
<meta property="og:url" content="http://blog.poetries.top/2017/10/21/json-stringify/index.html">
<meta property="og:site_name" content="Poetry&#39;s Blog">
<meta property="og:description" content="一、JSON.stringify参数详解 stringify方法顾名思义，就是把JSON序列化，其语法如下  JSON.stringify(value [, replacer] [, space])  value：是必选字段。就是你输入的对象、如数组等 replacer：这个是可选的。它又分为2种方式，一种是数组，第二种是方法【过滤函数，或者key的过滤数组（只有在数组中的会展示）】 情况一：re">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2020-08-15T04:25:31.926Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="浅析JSON.stringify">
<meta name="twitter:description" content="一、JSON.stringify参数详解 stringify方法顾名思义，就是把JSON序列化，其语法如下  JSON.stringify(value [, replacer] [, space])  value：是必选字段。就是你输入的对象、如数组等 replacer：这个是可选的。它又分为2种方式，一种是数组，第二种是方法【过滤函数，或者key的过滤数组（只有在数组中的会展示）】 情况一：re">

  

  
    <link rel="icon" href="/favicon.ico">
  

  <link href="/css/styles.css?v=c114cbeddx" rel="stylesheet">
<link href="/css/other.css?v=c114cbeddx" rel="stylesheet">


  
    <link rel="stylesheet" href="/css/personal-style.css">
  

  

  
  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?40b1f89aa80f2527b3db779c6898c879";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>


  
  <script type="text/javascript">
	(function(){
	    var bp = document.createElement('script');
	    var curProtocol = window.location.protocol.split(':')[0];
	    if (curProtocol === 'https') {
	        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
	    }
	    else {
	        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
	    }
	    var s = document.getElementsByTagName("script")[0];
	    s.parentNode.insertBefore(bp, s);
	})();
  </script>



  
    <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <link rel="stylesheet" href="//cdn.bootcss.com/font-awesome/4.3.0/css/font-awesome.min.css">
  

  <!-- 聊天系统 -->
  
    
   <link type="text/css" rel="stylesheet" href="/renxi/default.css">
   <style>
      #modal {
        position: static !important;
      }
      .filter {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        background: #fe5757;
        animation: colorChange 30s ease-in-out infinite;
        animation-fill-mode: both;
        mix-blend-mode: overlay;
      }
  
      @keyframes colorChange {
        0%, 100% {
            opacity: 0;
        }
        50% {
            opacity: .9;
        }
      }
   </style>
</head>
</html>
<body>
  
  
    <span id="toolbox-mobile" class="toolbox-mobile">导航</span>
  

  <div class="post-header CENTER">
   
  <div class="toolbox">
    <a class="toolbox-entry" href="/">
      <span class="toolbox-entry-text">导航</span>
      <i class="icon-angle-down"></i>
      <i class="icon-home"></i>
    </a>
    <ul class="list-toolbox">
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/archives/"
            rel="noopener noreferrer"
            target="_self"
            >
            博客
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/categories/"
            rel="noopener noreferrer"
            target="_self"
            >
            分类
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/tags/"
            rel="noopener noreferrer"
            target="_self"
            >
            标签
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/search/"
            rel="noopener noreferrer"
            target="_self"
            >
            搜索
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/link/"
            rel="noopener noreferrer"
            target="_self"
            >
            友链
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/about/"
            rel="noopener noreferrer"
            target="_self"
            >
            关于
          </a>
        </li>
      
    </ul>
  </div>


</div>


  <div id="toc" class="toc-article">
    <strong class="toc-title">文章目录<i class="iconfont toc-title" style="display:inline-block;color:#87998d;width:20px;height:20px;">&#xf004b;</i></strong>
    <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#一、JSON-stringify参数详解"><span class="toc-text">一、JSON.stringify参数详解</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#二、只传一个参数"><span class="toc-text">二、只传一个参数</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#三、传递两个参数的时候"><span class="toc-text">三、传递两个参数的时候</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#3-1-过滤函数"><span class="toc-text">3.1 过滤函数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-2-数组"><span class="toc-text">3.2 数组</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#四、传递三个参数的时候"><span class="toc-text">四、传递三个参数的时候</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#五、toJSON-方法"><span class="toc-text">五、toJSON 方法</span></a></li></ol>
  </div>
  




<div class="content content-post CENTER">
   <!-- canvas 彩带 -->
<canvas id="evanyou" width="1302" height="678" style="position: fixed;width: 100%;height: 100%;top: 0;left:0;z-index:-1;"></canvas>

<article id="post-json-stringify" class="article article-type-post" itemprop="blogPost">
  <header class="article-header" style="position:relative;">
    <h1 class="post-title">浅析JSON.stringify</h1>

    <div class="article-meta">
      <span>
        <i class="icon-calendar"></i>
        <span>2017.10.21</span>
      </span>

      
        <span class="article-author">
          <i class="icon-user"></i>
          <span>Poetry</span>
        </span>
      

      
  <span class="article-category">
    <i class="icon-list"></i>
    <a class="article-category-link" href="/categories/Front-End/">Front-End</a>
  </span>



      

      
      <i class="fa fa-eye"></i> 
        <span id="busuanzi_container_page_pv">
           &nbsp热度 <span id="busuanzi_value_page_pv">
           <i class="fa fa-spinner fa-spin"></i></span>℃
        </span>
      
      
       
          <span class="post-count">
            <i class="fa fa-file-word-o"></i>&nbsp
            <span>字数统计 1.2k字</span>
          </span>

          <span class="post-count">
            <i class="fa fa-columns"></i>&nbsp
            <span>阅读时长 4分</span>
          </span>
      
      
    </div>

    <i class="iconfont" id="toc-eye" style="display:inline-block;color:#b36619;position:absolute;top:0;right:0;cursor:pointer;
    font-size: 24px;">&#xe61c;</i>

  </header>

  <div class="article-content">
    
      <div id="container">
        <h2 id="一、JSON-stringify参数详解"><a href="#一、JSON-stringify参数详解" class="headerlink" title="一、JSON.stringify参数详解"></a>一、JSON.stringify参数详解</h2><ul>
<li><code>stringify</code>方法顾名思义，就是把<code>JSON</code>序列化，其语法如下</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="built_in">JSON</span>.stringify(value [, replacer] [, space])</span><br></pre></td></tr></table></figure>
<ul>
<li><code>value</code>：是必选字段。就是你输入的对象、如数组等</li>
<li><code>replacer</code>：这个是可选的。它又分为<code>2</code>种方式，一种是数组，第二种是方法【过滤函数，或者key的过滤数组（只有在数组中的会展示）】<ul>
<li>情况一：<code>replacer</code>为数组时，通过后面的实验可以知道，它是和第一个参数<code>value</code>有关系的。一般来说，系列化后的结果是通过键值对来进行表示的。 所以，如果此时第二个参数的值在第一个存在，那么就以第二个参数的值做key，第一个参数的值为value进行表示，如果不存在，就忽略。</li>
<li>情况二：<code>replacer</code>为方法时，那很简单，就是说把系列化后的每一个对象（记住是每一个）传进方法里面进行处理。 </li>
</ul>
</li>
<li><code>space</code>：就是用什么来做分隔符的【格式化前面的空格字符】<ul>
<li>如果省略的话，那么显示出来的值就没有分隔符，直接输出来</li>
<li>如果是一个数字的话，那么它就定义缩进几个字符，当然如果大于<code>10</code> ，则默认为<code>10</code>，因为最大值为<code>10</code></li>
<li>如果是一些转义字符，比如<code>\t</code>，表示回车，那么它每行一个回车。 </li>
<li>如果仅仅是字符串，就在每行输出值的时候把这些字符串附加上去。当然，最大长度也是<code>10</code>个字符</li>
</ul>
</li>
</ul>
<h2 id="二、只传一个参数"><a href="#二、只传一个参数" class="headerlink" title="二、只传一个参数"></a>二、只传一个参数</h2><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> obj = &#123;</span><br><span class="line">  name:<span class="string">"poetries"</span>,</span><br><span class="line">  age:<span class="number">22</span>,</span><br><span class="line">  job:<span class="string">"FED"</span>,</span><br><span class="line">  location:<span class="string">"shenzhen of China"</span></span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="built_in">JSON</span>.stringify(obj)  <span class="comment">//"&#123;"name":"poetries","age":22,"job":"FED","location":"shenzhen of China"&#125;"</span></span><br></pre></td></tr></table></figure>
<p><strong>注意点</strong></p>
<blockquote>
<p><code>JSON.stringify</code>对<code>obj</code>里面的数据类型有一些要求</p>
</blockquote>
<ul>
<li>非数组对象的属性不能保证以特定的顺序出现在序列化后的字符串中</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="built_in">JSON</span>.stringify(&#123;<span class="attr">x</span>: <span class="number">5</span>, <span class="attr">y</span>: <span class="number">6</span>&#125;) <span class="comment">// '&#123;"x":5,"y":6&#125;' 或者 '&#123;"y":6,"x":5&#125;' 都可能</span></span><br></pre></td></tr></table></figure>
<ul>
<li>布尔值、数字、字符串的包装对象在序列化过程中会自动转换成对应的原始值</li>
<li><code>undefined</code>、任意的函数以及 <code>symbol</code> 值，在序列化过程中会被忽略（出现在非数组对象的属性值中时）或者被转换成 <code>null</code>（出现在数组中时）</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> obj = &#123;</span><br><span class="line">  <span class="string">"undefined"</span>:<span class="literal">undefined</span>,</span><br><span class="line">  <span class="string">"null"</span>:<span class="literal">null</span>,</span><br><span class="line">  <span class="string">"true"</span>:<span class="literal">true</span>,</span><br><span class="line">  <span class="string">"func"</span>:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;&#125;,</span><br><span class="line">  <span class="string">"symbol"</span>:<span class="built_in">Symbol</span>(<span class="string">""</span>)</span><br><span class="line">&#125;;</span><br><span class="line"><span class="built_in">JSON</span>.stringify(obj); <span class="comment">//"&#123;"null":null,"true":true&#125;"</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 出现在数组中时被转化成null</span></span><br><span class="line"><span class="keyword">var</span> arr = [<span class="literal">undefined</span>,<span class="built_in">Symbol</span>(<span class="string">""</span>),<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;&#125;];</span><br><span class="line"><span class="built_in">JSON</span>.stringify(arr); <span class="comment">//[null,null,null]</span></span><br></pre></td></tr></table></figure>
<ul>
<li>不可枚举的属性会被忽略</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="built_in">JSON</span>.stringify( <span class="built_in">Object</span>.create(<span class="literal">null</span>, &#123; <span class="attr">x</span>: &#123; <span class="attr">value</span>: <span class="string">'x'</span>, <span class="attr">enumerable</span>: <span class="literal">false</span> &#125;, <span class="attr">y</span>: &#123; <span class="attr">value</span>: <span class="string">'y'</span>, <span class="attr">enumerable</span>: <span class="literal">true</span> &#125; &#125;) );</span><br><span class="line"><span class="comment">// '&#123;"y":"y"&#125;'</span></span><br></pre></td></tr></table></figure>
<h2 id="三、传递两个参数的时候"><a href="#三、传递两个参数的时候" class="headerlink" title="三、传递两个参数的时候"></a>三、传递两个参数的时候</h2><blockquote>
<ul>
<li>第二个参数可以是一个过滤函数，也可以是一个数组</li>
<li>当为数组时则只有包含在这个数组中的属性名才会被序列化到最终的 <code>JSON</code> 字符串中</li>
</ul>
</blockquote>
<h3 id="3-1-过滤函数"><a href="#3-1-过滤函数" class="headerlink" title="3.1 过滤函数"></a>3.1 过滤函数</h3><ul>
<li>注意点：<ul>
<li>这里一定要<code>return</code>一个值给下一个遍历函数作为参数传入，如果不<code>return</code>的话，后面的遍历就没法玩下去了</li>
</ul>
</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> obj = &#123;</span><br><span class="line">  name:<span class="string">"poetries"</span>,</span><br><span class="line">  age:<span class="number">22</span>,</span><br><span class="line">  job:<span class="string">"FED"</span>,</span><br><span class="line">  location:<span class="string">"shenzhen of China"</span></span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="built_in">JSON</span>.stringify(obj, (key,value) =&gt; &#123;</span><br><span class="line">   <span class="built_in">console</span>.log(key)</span><br><span class="line">   <span class="keyword">return</span> value; <span class="comment">// 这个是必须的，用于下一次的循环迭代</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<h3 id="3-2-数组"><a href="#3-2-数组" class="headerlink" title="3.2 数组"></a>3.2 数组</h3><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> obj = &#123;</span><br><span class="line">  name:<span class="string">"poetries"</span>,</span><br><span class="line">  age:<span class="number">22</span>,</span><br><span class="line">  job:<span class="string">"FED"</span>,</span><br><span class="line">  location:<span class="string">"shenzhen of China"</span></span><br><span class="line">&#125;;</span><br><span class="line"><span class="built_in">JSON</span>.stringify(obj, [<span class="string">"name"</span>, <span class="string">"age"</span>]);</span><br><span class="line"></span><br><span class="line"><span class="comment">//job、location由于不在列表里，所以没被序列化</span></span><br><span class="line"><span class="comment">//"&#123;"name":"poetries","age":22&#125;"</span></span><br></pre></td></tr></table></figure>
<h2 id="四、传递三个参数的时候"><a href="#四、传递三个参数的时候" class="headerlink" title="四、传递三个参数的时候"></a>四、传递三个参数的时候</h2><blockquote>
<p>第三参数space用来控制结果字符串里面的间距</p>
</blockquote>
<ul>
<li>如果是一个数字, 则在字符串化时每一级别会比上一级别缩进多这个数字值的空格（最多10个空格）</li>
<li>如果是一个字符串，则每一级别会比上一级别多缩进用该字符串（或该字符串的前十个字符）</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> obj = &#123;<span class="attr">name</span>:<span class="string">"poetries"</span>,<span class="attr">age</span>:<span class="number">22</span>,<span class="attr">job</span>:<span class="string">"FED"</span>,<span class="attr">location</span>:<span class="string">"shenzhen of China"</span>,<span class="attr">lov</span>:&#123;<span class="attr">age</span>:<span class="number">11</span>&#125;&#125;;</span><br><span class="line"><span class="built_in">JSON</span>.stringify(obj, <span class="literal">null</span>,<span class="number">10</span>);</span><br><span class="line"><span class="comment">// //每一个层级比上一个多10个空格</span></span><br><span class="line"><span class="string">"&#123;</span></span><br><span class="line"><span class="string">          "</span>name<span class="string">": "</span>poetries<span class="string">",</span></span><br><span class="line"><span class="string">          "</span>age<span class="string">": 22,</span></span><br><span class="line"><span class="string">          "</span>job<span class="string">": "</span>FED<span class="string">",</span></span><br><span class="line"><span class="string">          "</span>location<span class="string">": "</span>shenzhen <span class="keyword">of</span> China<span class="string">",</span></span><br><span class="line"><span class="string">          "</span>lov<span class="string">": &#123;</span></span><br><span class="line"><span class="string">                    "</span>age<span class="string">": 11</span></span><br><span class="line"><span class="string">          &#125;</span></span><br><span class="line"><span class="string">&#125;"</span></span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> obj = &#123;</span><br><span class="line">  name:<span class="string">"poetries"</span>,</span><br><span class="line">  age:<span class="number">22</span>,</span><br><span class="line">  job:<span class="string">"FED"</span>,</span><br><span class="line">  location:<span class="string">"shenzhen of China"</span>,</span><br><span class="line">  lov:&#123;</span><br><span class="line">    age:<span class="number">11</span></span><br><span class="line">  &#125;</span><br><span class="line">&#125;;</span><br><span class="line"><span class="built_in">JSON</span>.stringify(obj, <span class="literal">null</span>,<span class="string">"\n"</span>);</span><br><span class="line"><span class="comment">// 每一个层级比上一个多了一个回车符</span></span><br><span class="line"><span class="string">"&#123;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">"</span>name<span class="string">": "</span>poetries<span class="string">",</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">"</span>age<span class="string">": 22,</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">"</span>job<span class="string">": "</span>FED<span class="string">",</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">"</span>location<span class="string">": "</span>shenzhen <span class="keyword">of</span> China<span class="string">",</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">"</span>lov<span class="string">": &#123;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">"</span>age<span class="string">": 11</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&#125;</span></span><br><span class="line"><span class="string">&#125;"</span></span><br></pre></td></tr></table></figure>
<h2 id="五、toJSON-方法"><a href="#五、toJSON-方法" class="headerlink" title="五、toJSON 方法"></a>五、toJSON 方法</h2><blockquote>
<p>如果一个被序列化的对象拥有 <code>toJSON</code> 方法，那么该 <code>toJSON</code> 方法就会覆盖该对象默认的序列化行为</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> obj = &#123;</span><br><span class="line">  name:<span class="string">"poetries"</span>,</span><br><span class="line">  info:&#123;</span><br><span class="line">    age:<span class="number">18</span>,</span><br><span class="line">    sex:<span class="string">"male"</span></span><br><span class="line">  &#125;,</span><br><span class="line">  toJSON:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="string">"via toJSON"</span>;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="built_in">JSON</span>.stringify(obj); <span class="comment">// ""via toJSON""</span></span><br></pre></td></tr></table></figure>

      </div>
    
  </div>

</article>

<button class="assist-btn2 circle" id="assist_btn2" title="点亮屏幕" style="left: 27px; top: 152px;">
  <i class="iconfont" style="display:inline-block;color:red;width:20px;height:20px;">&#xe61d;</i>
</button>
<button class="assist-btn1 circle" id="assist_btn1" title="关闭屏幕亮度" style="left: 27px; top: 152px;">
  <i class="iconfont toc-title" style="display:inline-block;color:red;width:20px;height:20px;">&#xe61d;</i>
</button>


<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>	

<script src="https://my.openwrite.cn/js/readmore.js" type="text/javascript"></script>
<script>
  const btw = new BTWPlugin();
  btw.init({
    id: "container",
    blogId: "22699-1592137983091-414",
    name: "前端进阶之旅",
    qrcode: "https://poetries1.gitee.io/img-repo/2020/06/qrcode.jpg",
    keyword: "3a3b3c",
  });
</script>

<script type="text/javascript">

// white theme
var body = {color: "#555", background: "#000"};
var a_tag = {color: "#222"};
var header = { background: "#222"};
var logo_line_i = {background: "#222"};
// var post_code = {background: "#eee", color: "#222"};

function switch_theme() {
 $("body").css(body);
 $("a:not('.links-of-author-item a, .site-state-item a, .site-state-posts a, .feed-link a, .motion-element a, .post-tags a, .show-commit-cls a, #donate_board a')").css(a_tag);
 $(".header, .footer").css(header);
 $(".logo-line-before i, .logo-line-after i").css(logo_line_i);
 //$(".post code").css(post_code);
 $("#idhyt-surprise-ball #idhyt-surprise-ball-animation .drag").css(a_tag);
 $(".post-title-link, .posts-expand .post-meta, .post-comments-count, .disqus-comment-count, .post-category a, .post-nav-next a, .post-nav-item a").css(a_tag);
 
 // $("code").css({color: '#c5c8c6', background: '#1d1f21'});
 //$("#assist_btn1").hide(1500);
}

$(function () {
$("#assist_btn2").css("display","none");
 $("#assist_btn1").click(function() {
     switch_theme();
$("div#toc.toc-article").css({
 "background":"#eaeaea",
 "opacity":1
});
$(".toc-article ol").show();
$("#toc.toc-article .toc-title").css("color","#a98602");
$("#assist_btn1").css("display","none");
$("#assist_btn2").css("display","block");
 });
$("#assist_btn2").click(function() {
$("#assist_btn2").css("display","none");
$("#assist_btn1").css("display","block");
$("body").css("background","url(http://www.miaov.com/static/ie/images/news/bg.png)")
     $(".header, .footer").css("background","url(http://www.miaov.com/static/ie/images/news/bg.png)")
$(".toc-article ol").toggle(1000);
 });
});


//背景随机

var Y, O, E, L, B, C, T, z, N, S, A, I;
!function() {
var e = function() {
for (O.clearRect(0, 0, L, B), T = [{
x: 0,
y: .7 * B + C
}, {
x: 0,
y: .7 * B - C
}]; T[1].x < L + C;) t(T[0], T[1])
}, t = function(e, t) {
O.beginPath(), O.moveTo(e.x, e.y), O.lineTo(t.x, t.y);
var n = t.x + (2 * I() - .25) * C,
 r = a(t.y);
O.lineTo(n, r), O.closePath(), N -= S / -50, O.fillStyle = "#" + (127 * A(N) + 128 << 16 | 127 * A(N + S / 3) + 128 << 8 | 127 * A(N + S / 3 * 2) + 128).toString(16), O.fill(), T[0] = T[1], T[1] = {
 x: n,
 y: r
}
}, a = function n(e) {
var t = e + (2 * I() - 1.1) * C;
return t > B || t < 0 ? n(e) : t
};
Y = document.getElementById("evanyou"), O = Y.getContext("2d"), E = window.devicePixelRatio || 1, L = window.innerWidth, B = window.innerHeight, C = 90, z = Math, N = 0, S = 2 * z.PI, A = z.cos, I = z.random, Y.width = L * E, Y.height = B * E, O.scale(E, E), O.globalAlpha = .6, document.onclick = e, document.ontouchstart = e, e()
}()

   
$("#toc-eye").click(function(){
$("#toc.toc-article").toggle(1000);
});

</script>


   
  <div class="text-center donation">
    <div class="inner-donation">
      <span class="btn-donation">支持一下</span>
      <div class="donation-body">
        <div class="tip text-center">扫一扫，支持poetries</div>
        <ul>
        
          <li class="item">
            
              <span>微信扫一扫</span>
            
            <img src="/images/weixin.jpg" alt="">
          </li>
        
          <li class="item">
            
              <span>支付宝扫一扫</span>
            
            <img src="/images/zhifubao.jpg" alt="">
          </li>
        
        </ul>
      </div>
    </div>
  </div>


   
  <div class="box-prev-next clearfix">
    <a class="show pull-left" href="/2017/10/18/js-inherit-methods/">
        <i class="icon icon-angle-left"></i>
    </a>
    <a class="show pull-right" href="/2017/10/21/es6-review/">
        <i class="icon icon-angle-right"></i>
    </a>
  </div>




</div>


  <a id="backTop" class="back-top">
    <i class="icon-angle-up"></i>
  </a>




  <div class="modal" id="modal">
  <span id="cover" class="cover hide"></span>
  <div id="modal-dialog" class="modal-dialog hide-dialog">
    <div class="modal-header">
      <span id="close" class="btn-close">关闭</span>
    </div>
    <hr>
    <div class="modal-body">
      <ul class="list-toolbox">
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/archives/"
              rel="noopener noreferrer"
              target="_self"
              >
              博客
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/categories/"
              rel="noopener noreferrer"
              target="_self"
              >
              分类
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/tags/"
              rel="noopener noreferrer"
              target="_self"
              >
              标签
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/search/"
              rel="noopener noreferrer"
              target="_self"
              >
              搜索
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/link/"
              rel="noopener noreferrer"
              target="_self"
              >
              友链
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/about/"
              rel="noopener noreferrer"
              target="_self"
              >
              关于
            </a>
          </li>
        
      </ul>

    </div>
  </div>
</div>



  
      <div class="fexo-comments comments-post">
    

    

    
    

    

    
    

    

<!-- Gitalk评论插件通用代码 -->
<div id="gitalk-container"></div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
<script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>
<script>
const gitalk = new Gitalk({
  clientID: '5567a2c4abb858009d96',
  clientSecret: 'b9039ec056cf5c2346b3cdb63308a28c163f91e5',
  repo: 'poetries.github.io',
  owner: 'poetries',
  // 在这里设置一下截取前50个字符串, 这是因为 github 对 label 的长度有了要求, 如果超过
  // 50个字符串则会报错.
  // id: location.pathname.split('/').pop().substring(0, 49),
  id: location.pathname,
  admin: ['poetries'],
  // facebook-like distraction free mode
  distractionFreeMode: false
})
gitalk.render('gitalk-container')
</script>
<!-- Gitalk代码结束 -->



  </div>

  

  <script type="text/javascript">
  function loadScript(url, callback) {
    var script = document.createElement('script')
    script.type = 'text/javascript';

    if (script.readyState) { //IE
      script.onreadystatechange = function() {
        if (script.readyState == 'loaded' ||
          script.readyState == 'complete') {
          script.onreadystatechange = null;
          callback();
        }
      };
    } else { //Others
      script.onload = function() {
        callback();
      };
    }

    script.src = url;
    document.getElementsByTagName('head')[0].appendChild(script);
  }

  window.onload = function() {
    loadScript('/js/bundle.js?235683', function() {
      // load success
    });
  }
</script>


  <!-- 页面点击小红心 -->
  <script type="text/javascript" src="/js/clicklove.js"></script>
 
  
</body>
</html>
